package com.example.seatastorage;

import io.seata.spring.annotation.GlobalTransactional;
import java.util.Optional;
import javax.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author MoodAir
 */
@Service
@RequiredArgsConstructor
public class StorageService {
    
    private final StorageDao storageDao;
    
    
    private final SeataOrderFeign seataOrderFeign;
    
    @GlobalTransactional
    public void deduct(Long productId, Integer count) {
        Storage storage = storageDao.findByProductId(productId);
        if (storage != null) {
            storage.setTotal(storage.getTotal() - count);
            storageDao.save(storage);
            //订单
            seataOrderFeign.saveOrder(productId, count);
            int i = 1 / 0;
        }
    }
}
